package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class UpdateUserDemo {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("修改用户信息");
        System.out.println("请输入用户名:");
        String username = scanner.nextLine();
        System.out.println("请输入新的密码:");
        String password = scanner.nextLine();
        System.out.println("请输入新的昵称:");
        String nickname = scanner.nextLine();
        Connection connection=DBUtil.getConnection();
        System.out.println("与数据库链接成功!");
        Statement statement = connection.createStatement();
        String sql = "UPDATE userinfo " +
                "SET password='"+password+"',nickname='"+nickname+"' " +
                "WHERE username='"+username+"'";
        int num = statement.executeUpdate(sql);
        System.out.println(num>0?"修改成功":"用户名不存在");
        connection.close();
    }
}
